package com.example.chapp.control;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.chapp.MainActivity;
import com.example.chapp.R;
import com.example.chapp.entity.crose;
import com.example.chapp.entity.result;
import com.example.chapp.entity.user;
import com.example.chapp.listutil.*;
import com.example.chapp.util.HttpCallback;
import com.example.chapp.util.httputil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class shouyeactive extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shouye);
    request();

        View fl=findViewById(R.id.fl);
        fl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(shouyeactive.this,fenleiactive.class);
                startActivity(intent);
            }
        });
        View wd=findViewById(R.id.wd);
        wd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(shouyeactive.this, wodeactive.class);
                startActivity(intent);
            }
        });


    }

    public void request() {

        httputil.sendRequest(netutil.url, "GET", null, new HttpCallback() {
            @Override
            public void onSuccess(InputStream in) {
                Gson gson=new Gson();
                result r=gson.fromJson(httputil.decodeAsString(in),new TypeToken<result<List<String>>>(){}.getType());
                List<String> data= (List<String>) r.getData();
                shouyelist shouyelist=new shouyelist(data,shouyeactive.this);
                ListView listView=findViewById(R.id.sylist);
                listView.setAdapter(shouyelist);
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        Intent intent=new Intent(shouyeactive.this, study1activity.class);
                        startActivity(intent);
                    }
                });
            }

            @Override
            public void onFailure(int code, String mes) {

            }
        });
    }
}
